package servlet.huwenyao;

import pojo.Evaluate;
import pojo.Goods;
import pojo.Order;
import pojo.User;
import service.EvaluateService;
import service.OrderService;
import service.impl.EvaluateServiceImpl;
import service.impl.OrderServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

/**
 * 修改订单回显Servlet页面
 */
@WebServlet(value = "/UpdataOrderEchoServlet")
public class UpdataOrderEchoServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //当前返回的是JSON格式
        response.setContentType("text/json;charset=UTF-8");
        //接收页面的订单id
        String id = request.getParameter("id");
        OrderService orderService=new OrderServiceImpl();
        //获取当前订单对象
        Order order=orderService.finaOrder(Integer.parseInt(id));
        //根据订单对象的商品id查询商品名称
        Goods goods=new Goods();
        String wareId[]= order.getWareId().split(",");
        for(int i=0;i<wareId.length;i++){
            goods.setGoName(orderService.finaGoods(Integer.parseInt(wareId[i])).getGoName());
        }
        //根据订单对象的用户id查询用户对象
        User user=orderService.finaUser(order.getConsumerId());
        //保存变量并将数据转发到jsp页面
        request.setAttribute("user",user);
        request.setAttribute("order",order);
        request.setAttribute("goods", goods);
        request.getRequestDispatcher("jsp/hwy/UpdateOrder.jsp").forward(request,response);
    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
     doPost(request,response);
    }
}
